package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.StoreBrowseDAO;
import com.xinghou.platform.model.main.StoreBrowse;

@Service
public class StoreBrowseDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public StoreBrowse getStoreBrowseByid(Integer Id) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT Id,User_id,Store_id,Browse_type,Create_time,Update_time FROM store_browse where Id = ?";
		StoreBrowse StoreBrowse = jdbcTemplate.queryForObject(sql, new Object[] {Id}, new StoreBrowseMapper());
		CustomerContextHolder.clearCustomerType();
		return StoreBrowse;
	}

	@Override
	public int updateStoreBrowse(StoreBrowse StoreBrowse) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE store_browse SET User_id =? ,Store_id =?,Browse_type =?, Create_time =?, Update_time = ? Where Id =?");
		Object[] params = {StoreBrowse.getUserId(), StoreBrowse.getStoreId(), StoreBrowse.getBrowseType(), 
				StoreBrowse.getCreateTime(), StoreBrowse.getUpdateTime(), StoreBrowse.getId()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveStoreBrowse(StoreBrowse StoreBrowse) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"INSERT INTO store_browse (User_id,Store_id,Browse_type,Create_time, Update_time)VALUES(?,?,?,?,?)");
		Object[] params = {StoreBrowse.getUserId(), StoreBrowse.getStoreId(), StoreBrowse.getBrowseType(), 
				StoreBrowse.getCreateTime(),StoreBrowse.getUpdateTime()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret =jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	
	@Override
	public StoreBrowse getStoreBrowseBytwo(Integer userId, Integer cardId) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT Id,User_id,Store_id,Browse_type,Create_time,Update_time FROM store_browse where User_id = ? and Store_id=?";
		StoreBrowse StoreBrowse = jdbcTemplate.queryForObject(sql, new Object[] {userId,cardId}, new StoreBrowseMapper());
		CustomerContextHolder.clearCustomerType();
		return StoreBrowse;
	}

	@Override
	public List<StoreBrowse> getStoreListByUserId(int storeId, int rowNum)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql="SELECT Id,User_id,Store_id,Browse_type,Create_time,Update_time FROM store_browse where Store_id=? ORDER BY Update_time DESC LIMIT ?";
		List<StoreBrowse> list = jdbcTemplate.query(sql, new Object[] {storeId,rowNum}, new StoreBrowseMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}
	
	private static final class StoreBrowseMapper implements RowMapper<StoreBrowse> {
		public StoreBrowse mapRow(ResultSet rs, int rowNum) throws SQLException {
			StoreBrowse StoreBrowse = new StoreBrowse();
			StoreBrowse.setId(rs.getInt("Id"));
			StoreBrowse.setBrowseType(rs.getShort("Browse_type"));
			StoreBrowse.setStoreId(rs.getInt("Store_id"));
			StoreBrowse.setCreateTime(rs.getTimestamp("Create_time"));
			StoreBrowse.setUpdateTime(rs.getTimestamp("Update_time"));
			StoreBrowse.setUserId(rs.getInt("User_id"));
			return StoreBrowse;
		}
	}
*/
	
}
